$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'styj1/b3citydevelopmentstrenth/list',
        datatype: "json",
        colModel: [			
			{ label: 'cityStrenthId', name: 'cityStrenthId', index: 'city_strenth_id', width: 50, key: true },
			{ label: '居住用地容积率', name: 'residentialLand1', index: 'residential_land1', width: 80 }, 			
			{ label: '居住用地建筑密度', name: 'residentialLand2', index: 'residential_land2', width: 80 }, 			
			{ label: '公共管理与公共服务用地容积率', name: 'publicAdministrationAndServices1', index: 'public_administration_and_services1', width: 80 }, 			
			{ label: '公共管理与公共服务用地建筑密度', name: 'publicAdministrationAndServices2', index: 'public_administration_and_services2', width: 80 }, 			
			{ label: '商业服务业设施用地容积率', name: 'acilitiesForCommercialServices1', index: 'acilities_for_commercial_services1', width: 80 }, 			
			{ label: '商业设施服务用地建筑密度', name: 'acilitiesForCommercialServices2', index: 'acilities_for_commercial_services2', width: 80 }, 			
			{ label: '工业用地容积率', name: 'industryLand1', index: 'industry_land1', width: 80 }, 			
			{ label: '工业用地建筑密度', name: 'industryLand2', index: 'industry_land2', width: 80 }, 			
			{ label: '物流仓储用地容积率', name: 'logisticsStorageSites1', index: 'logistics_storage_sites1', width: 80 }, 			
			{ label: '物流仓储用地建筑密度', name: 'logisticsStorageSites2', index: 'logistics_storage_sites2', width: 80 }, 			
			{ label: '道路与交通设施用地容积率', name: 'roadSite1', index: 'road_site1', width: 80 }, 			
			{ label: '道路与交通设施用地建筑密度', name: 'roadSite2', index: 'road_site2', width: 80 }, 			
			{ label: '公用设施用地容积率', name: 'publicSite1', index: 'public_site1', width: 80 }, 			
			{ label: '公用设施用地建筑密度', name: 'publicSite2', index: 'public_site2', width: 80 }, 			
			{ label: '绿地广场用地容积率', name: 'greenlandSite1', index: 'greenland_site1', width: 80 }, 			
			{ label: '绿地广场用地建筑密度', name: 'greenlandSite2', index: 'greenland_site2', width: 80 }, 			
			{ label: '文件路径', name: 'filePath', index: 'file_path', width: 80 }, 			
			{ label: '录入人', name: 'creatby', index: 'creatby', width: 80 }, 			
			{ label: '录入时间', name: 'update', index: 'update', width: 80 }, 			
			{ label: '上级部门', name: 'parentCode', index: 'parent_code', width: 80 }, 			
			{ label: '类型编码', name: 'typeCode', index: 'type_code', width: 80 }, 			
			{ label: '更新时间', name: 'updateTime', index: 'update_time', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q:{
            name: null
        },
		showList: true,
        flag:true,
		title: null,
		b3CityDevelopmentStrenth: {}
	},
    mounted:function(){
        this.initonezb();
    },
	methods: {

		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
            vm.flag=false;
			vm.b3CityDevelopmentStrenth = {};
		},
		update: function (event) {
			var cityStrenthId = getSelectedRow();
			if(cityStrenthId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            vm.flag=true;
            
            vm.getInfo(cityStrenthId)
		},
		saveOrUpdate: function (event) {
            if(!$('form').data("bootstrapValidator").isValid()){
                alert("表单验证没通过");
                return;
            };
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.b3CityDevelopmentStrenth.cityStrenthId == null ? "styj1/b3citydevelopmentstrenth/save" : "styj1/b3citydevelopmentstrenth/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.b3CityDevelopmentStrenth),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var cityStrenthIds = getSelectedRows();
			if(cityStrenthIds == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "styj1/b3citydevelopmentstrenth/delete",
                        contentType: "application/json",
                        data: JSON.stringify(cityStrenthIds),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
		getInfo: function(cityStrenthId){
			$.get(baseURL + "styj1/b3citydevelopmentstrenth/info/"+cityStrenthId, function(r){
                vm.b3CityDevelopmentStrenth = r.b3CityDevelopmentStrenth;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'name': vm.q.name},
                page:page
            }).trigger("reloadGrid");
		}
	}
});


$(function () {
    $('form').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {

        }

    });
});

// Validate the form manually
$('#validateBtn').click(function() {
    $('form').bootstrapValidator('validate');
});

$('#resetBtn').click(function() {
    $('form').data('bootstrapValidator').resetForm(true);
});
